package it.webrules.deploymanager.core.utils;

import java.net.HttpURLConnection;

import javax.xml.bind.DatatypeConverter;

public class BasicAuth {

	private BasicAuth() {
	}

	public static void setBasicAuth(HttpURLConnection connection, String username, String password) {

		if (username != null && !username.isEmpty()) {
			String userpassword = username + ":" + password;
			String encodedAuthorization = DatatypeConverter.printBase64Binary(userpassword.getBytes());
			connection.setRequestProperty("Authorization", "Basic " + encodedAuthorization);
		}

	}

}
